home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / musik / MIDIFP21 / SOURCES / MIDI_PRT / INFO / INFO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-24  |  4.3 KB  |  156 lines

  1. /**************************************************************
  2. *
  3. *                INFO.C
  4. *
  5. **************************************************************/
  6.  
  7. #include <acs.h>
  8. #include <acsplus.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <messages.pif>   /* for use of self-built library */
  12. #include <acs_plus.pif>   /* for use of self-built library */
  13. #include <servimem.pif>   /* for use of self-built library */
  14.  
  15. #include "info.pif"
  16. #include "info.h"
  17. #include "info.ah"
  18.  
  19.  
  20. /*******************************************************************
  21. */
  22.     static void keys(Awindow *wi, int kstate, int key)
  23. /*
  24. *   Keyboard procedure of the info window. See also ACS manual.
  25. *
  26. *******************************************************************/
  27. {
  28.     /*** inform other windows about key pressure ***/
  29.     key_message.sender = wi ;
  30.     key_message.kstate = kstate ;
  31.     key_message.key    = key ;
  32.     Awi_sendall(KEY_PRESS, &key_message) ;
  33.  
  34.     /*** forward event to ACS for further treatment (e.g. by the desktop) ***/
  35.     Awi_keys(wi, kstate, key) ;
  36. }
  37.  
  38.  
  39. /*******************************************************************
  40. */
  41.     static int service(Awindow *wi, int task, void *not_used)
  42. /*
  43. * Service routine for messages sent to this window.
  44. * See also ACS manual.
  45. * OUTPUT:  AS_TERM ==> message is forwarded to parent
  46. *          AS_INFO ==> a little help function 
  47. *******************************************************************/
  48. {
  49.     switch (task)
  50.     {    
  51.         case AS_TERM: Awi_sendall(TERMINATE, wi) ; break ; 
  52.         case AS_INFO: A_dialog(&INFO_INFO) ; break ;
  53.         default:      return FALSE ;
  54.     }
  55.     return TRUE ;    /* task has been treated */
  56. }
  57.  
  58.  
  59. /*******************************************************************
  60. *
  61. *                  PUBLISHED INTERFACE
  62. *
  63. *******************************************************************/
  64.  
  65.  
  66. void set_transformed_size(Awindow *wi, long transformed_size)
  67.     ltoa( transformed_size >> 10 /* in units of 1024 Byte */, 
  68.           wi->work[TRANSFORMED_SIZE].ob_spec.tedinfo->te_ptext, 10) ;
  69.     Awi_obchange(wi, TRANSFORMED_SIZE, 
  70.           wi->work[TRANSFORMED_SIZE].ob_state &= ~DISABLED) ;
  71. }
  72.  
  73.  
  74. unsigned int get_number_of_tracks(Awindow *wi)
  75. { return atoi( wi->work[NUMBER_OF_TRACKS].ob_spec.tedinfo->te_ptext ) ; }
  76.  
  77.  
  78. int get_ticks_per_beat(Awindow *wi)
  79. { return atoi( wi->work[TICKS_PER_BEAT].ob_spec.tedinfo->te_ptext ) ; }
  80.  
  81.  
  82. int get_SMPTE(Awindow *wi)
  83. {
  84.     if ( wi->work[SMPTE].ob_state & DISABLED ) return FALSE ;
  85.     else return TRUE ;
  86. }
  87.  
  88.  
  89. void INFO_destructor(Awindow *wi)
  90.     if (wi) 
  91.     {
  92.         memory_symptom = "InDstr wi" ; 
  93.         Awi_delete(wi) ; 
  94.     }
  95. }
  96.  
  97.  
  98. Awindow *INFO_constructor(INFO_INIT *info_init)
  99. {
  100. Awindow *wi ;
  101. char MThd[5] = "MThd" ;
  102. unsigned int division = 0 ; 
  103.  
  104.     /*** enter filename into icon text ***/
  105.     INFO_WINDOW.iconblk = info_init->icon ;
  106.     INFO_WINDOW.iconblk->monoblk.ib_ptext = 
  107.     INFO_WINDOW.info = info_init->filename ;
  108.  
  109.     /*** create the INFO window ***/
  110.     wi = Awi_create(&INFO_WINDOW) ;
  111.     if (!wi) return NULL ;
  112.  
  113.     /*** already known data, enter into GEM-object ***/
  114.     ltoa( info_init->filesize >> 10 /* in units of 1024 Byte */, 
  115.          wi->work[FILE_SIZE].ob_spec.tedinfo->te_ptext, 10 ) ;
  116.     /*** evaluate header chunk ***/
  117.     if ( memcmp(MThd, info_init->RAM_file, 4) )
  118.     {
  119.         /*** no correct MIDI file format ***/
  120.         alert_str(INVALID_FORMAT, wi->iconblk->monoblk.ib_ptext) ;
  121.         INFO_destructor(wi) ;
  122.         return NULL ;
  123.     }
  124.     /*** continue evaluating header chunk: ***/
  125.     /*** type of MIDI file ***/
  126.     itoa( read_int(info_init->RAM_file + 4 + 4), 
  127.        wi->work[MIDI_FILE_TYPE].ob_spec.tedinfo->te_ptext, 16 ) ;
  128.     /*** number of tracks in MIDI file ***/
  129.     itoa( read_int(info_init->RAM_file + 4 + 4 + 2), 
  130.        wi->work[NUMBER_OF_TRACKS].ob_spec.tedinfo->te_ptext, 10 ) ;
  131.     /*** time division ***/
  132.     division = read_int(info_init->RAM_file + 4 + 4 + 2 + 2) ;
  133.     if (division & 0x1000)
  134.     {
  135.         /*** SMPTE format ***/
  136.         wi->work[TICKS_PER_BEAT].ob_state |= DISABLED ;
  137.         itoa( (-division) >> 8, wi->work[SMPTE].ob_spec.tedinfo->te_ptext, 10 ) ;
  138.         itoa( division & 0xff, wi->work[TICKS_PER_FRAME].ob_spec.tedinfo->te_ptext, 10 ) ;
  139.     }
  140.     else 
  141.     {
  142.         /*** non-SMPTE format ***/
  143.         wi->work[SMPTE].ob_state |= DISABLED ;
  144.         wi->work[TICKS_PER_FRAME].ob_state |= DISABLED ;
  145.         itoa( division, wi->work[TICKS_PER_BEAT].ob_spec.tedinfo->te_ptext, 10 ) ;
  146.     }
  147.     /*** return success message ***/
  148.     return wi ;
  149. }
  150.  
  151.  
  152.